package catering

import (
	"gitcode.com/G-YT/iHealth25/server/model/common/response"
	"github.com/gin-gonic/gin"
	"time"
)

type DateApi struct {
}

func (dateApi *DateApi) GetDate(c *gin.Context) {
	// Get the current date
	currentDate := time.Now()

	// Calculate the start date of the week (Sunday)
	startDate := currentDate.AddDate(0, 0, -int(currentDate.Weekday())+1)

	// Create an array to hold the week information
	var weekInfo []map[string]interface{}

	// Loop through each day of the week
	for i := 0; i < 7; i++ {
		// Calculate the date of the current day
		currentDate := startDate.AddDate(0, 0, i)

		// Determine if the current day is today
		isToday := currentDate.Year() == time.Now().Year() &&
			currentDate.Month() == time.Now().Month() &&
			currentDate.Day() == time.Now().Day()

		// Add the week information to the array
		weekInfo = append(weekInfo, map[string]interface{}{
			"key":     currentDate.Day(),
			"week":    currentDate.Weekday(),
			"istoday": isToday,
		})
	}
	response.Result(200, weekInfo, "获取成功", c)
}
